<template>
  <div>
    <el-table :data="tableList"  v-loading="loading" @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="center" prop="patientId" />
      <el-table-column prop="diagnoseTime" label="问诊时间" align="center" />
      <el-table-column prop="patientName" label="姓名" align="center" />
      <el-table-column prop="patientAge" label="年龄" align="center" />
      <el-table-column prop="consultationFee" label="支付问诊金额" align="center" />
      <el-table-column prop="diagnosis" label="病情" align="center" />
      <el-table-column prop="doctorName" label="问诊医生姓名" align="center" />
      <el-table-column prop="rankOfPhysician" label="问诊医生职称" v-if="rankOfPhysician==1" align="center" >普通医师</el-table-column>
      <el-table-column prop="hospitalName" label="医院" align="center" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button plain  @click="dialogTableVisible1(scope.row.patientName)">诊断报告</el-button>

          <el-dialog v-model="dialogTableVisible" title="诊断报告" width="800">
            <el-table :data="gridData">
              <el-table-column property="diagnoseTime" label="时间" width="150" />
              <el-table-column property="patientName" label="患者姓名" width="200" />
              <el-table-column property="patientAge" label="年龄" width="200" />
              <el-table-column property="patientHeight" label="身高" width="200" />
              <el-table-column property="patientWeight" label="体重" width="200" />
              <el-table-column property="renalFunction" label="肾功能" width="200" />
              <el-table-column property="fertulityStatus" label="生育状况" width="200" />
              <el-table-column property="diseasesHistory" label="疾病史" width="200" />
              <el-table-column property="liverFunction" label="肝功能" width="200" />
              <el-table-column property="message" label="病情描述" width="200" />
              <el-table-column property="diagnoseResult" label="诊断" width="200" />
            </el-table>
          </el-dialog>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script setup name="patientIn">
import { listPatient} from "@/api/manage/PatientManagement.js";
import {useRoute, useRouter} from "vue-router";
import { reactive, ref } from 'vue'
import {listMedical} from "@/api/manage/PatientManagement.js";

const { proxy } = getCurrentInstance();


const open = ref(false);
const gridData = ref([]);
const dialogTableVisible = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);


const multiple = ref(true);
const tableList = ref([]);
const total = ref(0);
const title = ref("");
const route = useRoute();
const router = useRouter();


let  patientName= route.query.patientName;
let  rankOfPhysician= route.query.patientName;


const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    patientName: null,
  },
  rules: {
  }
});

const { form,rules,queryParams } = toRefs(data)

function dialogTableVisible1(patientName){


  listMedical(patientName).then(response => {
    console.log(response)
    gridData.value = response.data;

    // total.value = response.data.total;
    loading.value = false;
  });

  dialogTableVisible.value = true
  console.log(patientName)
  //router.push({query:{patientName:patientName}});
}



/** 查询医师列表 */
function getList() {

  loading.value = true;

  listPatient(patientName).then(response => {

    console.log(response)
    tableList.value= response.data;
    total.value = response.data.total;
    loading.value = false;

  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.departmentId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

getList();

</script>

